import sys


class ParamsTypeError(Exception):
    pass


# 获取斐波那契数列的起始两个数字
def num():
    print('fibonacci函数实现斐波那契数列，请输入初始整数数字x,y，用逗号分隔，且x<y')
    str1 = input()
    list1 = str1.split(',')
    try:
        x0 = int(list1[0])
        x1 = int(list1[1])
    except ValueError:
        print("请重试并用','分隔整数")
        sys.exit(0)
    return x0, x1

# top函数用来获取数列的上限
def top():
    toplimit = 0 # python认为toplimit在下面可能无法被赋值，预先赋值排除error警报
    print('请输入斐波那契数列上限')
    try:
        toplimit = int(input())
    except ValueError:
        print('请输入整数')
    while x0 > toplimit or x1 > toplimit:
        try:
            toplimit = int(input())
            print('上限过小，请重新输入')
        except ValueError:
            try:
                print('请输入整数')
                toplimit = int(input())
            except:
                raise ParamsTypeError('错误的数据类型')
    return toplimit


# fibonacci函数用来循环计算
def fibonacci(x, y, z):
    print('上限为{2}的斐波那契数列为\n{0}\n{1}'.format(x, y, z))
    while True:
        if x + y > z:
            break
        tmp = x + y
        x = y
        y = tmp
        print(tmp)
    return (x, y)


# 顺序调用函数
x0, x1 = num()
toplimit = top()
if x0 < x1:
    fibonacci(x0, x1, toplimit)
else:
    fibonacci(x1, x0, toplimit)

